import java.util.ArrayList;


public class java8 {
    public static void main(String[] args) {
        String str = "abcabcbb";
        int maxLength = lengthOfLongestSubstring(str);
        System.out.println("不含重复字符的最长子串长度为：" + maxLength);  // 输出：不含重复字符的最长子串长度为：3
    }

    public static int lengthOfLongestSubstring(String s) {
        int n = s.length();
        int maxLength = 0;
        ArrayList<Character> list = new ArrayList<>();

        int i = 0;
        int j = 0;
        while (j < n) {
            if (!list.contains(s.charAt(j))) {
                list.add(s.charAt(j));
                j++;
                maxLength = Math.max(maxLength, list.size());
            } else {
                list.remove(0);
                i++;
            }
        }

        return maxLength;
    }
}
